<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>

		<script type="text/javascript">
			function foo(filePath) {
				var lastSlashIndex = filePath.lastIndexOf("/");
				var directoryPath = filePath.substring(0, lastSlashIndex + 1);
				console.log("文件所在路径:", directoryPath);

				var fileNameWithExtension = filePath.substring(lastSlashIndex + 1);
				console.log("完整文件名:", fileNameWithExtension);

				var dotIndex = fileNameWithExtension.lastIndexOf(".");
				var fileName = fileNameWithExtension.substring(0, dotIndex);
				console.log("文件名:", fileName);

				var fileExtension = fileNameWithExtension.substring(dotIndex);
				console.log("文件名后缀:", fileExtension);
			}

			var filePath = "d:/abc/bbb/aaa.txt";
			document.write(foo(filePath));
			filePath = "c:/1.txt";
			foo(filePath);
			filePath = "e:/资料/2.html";
			foo(filePath);
		</script>

	</body>
</html>
